<template>
  <div>
    <!-- 短信验证码 -->
    <van-dialog
      v-model="show"
      title="短信验证码"
      show-cancel-button
      @select="sheetSelect"
    >
      <div class="verificationCode-center">
        <p>验证码</p>
        <input type="text" placeholder="6位短信验证码" id="Y1six" />
        <div @click="startTimer" id="Y1gain" v-if="codeShow">获取验证码</div>
        <!-- 倒计时 -->
        <span v-if="!codeShow" class="count">{{ count }}秒后重试</span>
      </div>
      <div class="verificationCode-top">
        <div id="Y1phone">
          验证码发送至手机号<span id="num1">{{ phone }}</span>
        </div>
      </div>
    </van-dialog>
    <div class="D6main">
      <div class="D6nav">
        <a href=""> <img src="../assets/img/返回箭头.png" alt="" /> </a>
        <span>注册</span>
      </div>
      <div class="D6number">
        <div class="D6headd"></div>
        <p>{{ phone }}</p>
      </div>
      <div class="D6input">
        <input
          type="password"
          placeholder="请输入注册密码"
          id="D6password"
          v-model="password"
        />
        <button id="D6register" @click="fun">注册</button>
      </div>
      <div class="D6option">
        <a href="">切换/登录用户</a>
        <a href="">登录帮助</a>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      btn: false,
      show: false,
      codeShow: true,
      count: "",
      timer: null,
      password: "",
      phone:this.$route.params.Number,
    };
  },
  methods: {
    // 弹框
    fun() {
      if (D6password.value == "") {
        Dialog({ title: "温馨提示", message: "密码不能为空，请重新输入" });
      } else {
        this.show = true;
      }
    },
    sheetSelect(item) {
      // console.log(item.name);
      if (item.name == "确定") {
        regp1({ password: this.password })
          .then((res) => {
            // console.log(res);
            if (res.code == 200) {
              this.$router.push({
              name: "Register",
              params: {},
            });
            }else{
              Dialog({title: '温馨提示', message: res.mag });
            }
          })
          .catch((err) => {
            console.log("失败");
          });
      }
    },
    // 验证码
    startTimer() {
      const TIME_COUNT = 60;
      if (!this.timer) {
        this.count = TIME_COUNT;
        this.codeShow = false;
        this.timer = setInterval(() => {
          if (this.count > 0 && this.count <= TIME_COUNT) {
            this.count--;
          } else {
            this.codeShow = true;
            clearInterval(this.timer);
            this.timer = null;
          }
        }, 1000);
      }
      let code = {
        mobile: this.mobile,
        sms_type: "login",
      };
      //   验证码接口
      reg1({})
        .then((res) => {})
        .catch((err) => {
          console.log("失败");
        });
    },
  },
};
</script>

<style scoped src="../assets/css/register1.css">
</style>